<?php
class tagsController extends AppController {

	var $name = 'tags';

    function beforeFilter () {
        parent::beforeFilter();
    }

	function index() {
		$this->tag->recursive = 0;
		$this->set('tags', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid tag', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('tag', $this->tag->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->tag->create();
			if ($this->tag->save($this->data)) {
				$this->Session->setFlash(__('The tag has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The tag could not be saved. Please, try again.', true));
			}
		}
		$problems = $this->tag->Problem->find('list');
		$this->set(compact('problems'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid tag', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->tag->save($this->data)) {
				$this->Session->setFlash(__('The tag has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The tag could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->tag->read(null, $id);
		}
		$problems = $this->tag->Problem->find('list');
		$this->set(compact('problems'));
	}
}
?>